package com.byzk.p2p.admin.system.controller;


import java.util.Date;

import org.jsoup.helper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.JsonMsg;
import com.byzk.p2p.admin.system.dto.SEO;
import com.byzk.p2p.admin.system.service.SEOService;

/**
 * 还款方式设置
 * @author LiuJY
 *
 */
@Controller
@RequestMapping("/admin/seo")
public class SEOController extends AdminBaseController {

	@Autowired
	private SEOService seoService;
	
	@RequestMapping("/settingSeo")
	public String settingSeo(Model model) {
		return ftl(Thread.currentThread().getStackTrace());
	}
	/**
	 * 保存seo
	 * @param seo
	 * @return
	 */
	@RequestMapping(value="/save")
	public void saveSEO(@RequestBody SEO seo) {
		try {
			if (getUserId() == null) {
				super.printJSON(new JsonMsg(0, "请先登录！"));
				return;
			}
			if(StringUtil.isBlank(seo.getKeyword())){
				printJSON(new JsonMsg(1, "关键字不能为空"));
				return;
			}
			seo.setCreateUserId(getUserId());
			seo.setCreateTime(new Date());
			Integer i = seoService.saveOrUpdate(seo);
			if (i > 0) {
				super.printJSON(new JsonMsg(-1, "操作成功"));
			} else {
				super.printJSON(new JsonMsg(0, "操作失败"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
